<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<c:set var="totalPages" value="${page.totalPages}" />
<c:set var="totalElements" value="${page.totalElements}" />
<c:set var="number" value="${page.number + 1}" />
<c:set var="size" value="${page.size}" />


<c:set var="visiblePages" value="9" /> <!-- 总共显示的页码 value="奇数 并且 大于等于5" -->
<c:set var="visiblePagesHalf" value="${(visiblePages - 1) / 2}" />  <!-- 当前页左右的页码 -->
<c:set var="begin" value="1" /> <!-- 默认起始页 -->
<c:set var="end" value="${totalPages}" />   <!-- 默认结束页 -->

<style type="text/css">
    .number {
        background-color: #eee;
    }
</style>

共 ${page.totalElements} 条记录
<div class="btn-group pull-right">
        <c:if test="${totalPages > visiblePages}">
            <c:if test="${number + visiblePagesHalf <= totalPages}">
                <c:set var="end" value="${number + visiblePagesHalf}" />
                <c:if test="${end <= visiblePages}">
                    <c:set var="end" value="${visiblePages}" />
                </c:if>
            </c:if>
            <c:if test="${number - visiblePagesHalf > 0}">
                <c:set var="begin" value="${number - visiblePagesHalf}" />
                <c:if test="${end - begin + 1 < visiblePages}">
                    <c:set var="begin" value="${end - visiblePages + 1}" />
                </c:if>
            </c:if>
        </c:if>

        <a href="javascript:loadTable(${number - 1 > 1 ? number - 1 : 1});" class="btn btn-default ${number - 1 < 1 ? 'disabled disabled-link' : ''}">上一页</a>

        <c:if test="${begin > 1}">
            <a href="javascript:loadTable(1);" class="btn btn-default">1</a>
            <c:set var="begin" value="${begin + 1}" />
        </c:if>
        
        <c:forEach begin="${begin}" end="${end}" varStatus="status">
            <c:choose>
                <c:when test="${status.index == end && end < totalPages}">
                    <a href="javascript:loadTable(${totalPages});" class="btn btn-default">${totalPages}</a>
                </c:when>
                <c:otherwise>
                    <a href="javascript:loadTable(${status.index});" class="btn btn-default ${status.index == number ? 'blue' : ''}">${status.index}</a>
                </c:otherwise>
            </c:choose>
        </c:forEach>

        <a href="javascript:loadTable(${number + 1 < totalPages ? number + 1 : totalPages});" class="btn btn-default ${number + 1 > totalPages ? 'disabled disabled-link' : ''}">下一页</a>
</div>
<div class="clearfix"></div>